package com.yy.smartBI.controller;

import com.yy.smartBI.config.ThreadPoolConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;

@RestController
@RequestMapping("/queue")
@Slf4j
public class QueueController {
    @Resource
    private ThreadPoolExecutor threadPoolExecutor;

    @GetMapping("/create")
    public void createTask(){
        CompletableFuture.runAsync(()->{
            log.info("创建并执行任务");
            try {
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },threadPoolExecutor);
    }

    @GetMapping("/get")
    public String getTaskInfo(){
        return "当前线程池信息：{}"+threadPoolExecutor.toString()+
                "当前线程池队列信息：{}"+threadPoolExecutor.getQueue().toString() +
                "当前线程池线程信息：{}"+threadPoolExecutor.getPoolSize()+
                "当前线程池任务信息：{}"+threadPoolExecutor.getTaskCount()+
                "正在执行线程"+Thread.currentThread().getName();
    }

}
